package com.zb.validation.demo.controller;

import com.zb.validation.demo.model.PersonGroup;
import com.zb.validation.demo.model.validation.SaveValidation;
import com.zb.validation.demo.model.validation.UpdateValidation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;

/**
 * Validation分组校验
 *
 * @author ZB
 * @version 1.0
 * @since 1.0
 */
@Slf4j
@RestController
@RequestMapping("/demo-4")
public class Demo4Controller {

    @PostMapping("/save-1")
    public HttpStatus save1(@Validated(value = {SaveValidation.class, Default.class}) @RequestBody PersonGroup person) {
        log.info("person is {}", person);

        return HttpStatus.OK;
    }

    @PostMapping("/update-1")
    public HttpStatus update1(@Validated(value = {UpdateValidation.class, Default.class}) @RequestBody PersonGroup person) {
        log.info("person is {}", person);

        return HttpStatus.OK;
    }

}
